
  {extend name="public/base"}
  {block name="x-body"}
  <style>
      .layui-form-item .layui-input-inline {
          width: 340px;
      }

      #test9 {
          display: none;
      }

      #demo1{
          width: 200px;
      }
  </style>
    <div class="x-body">
        <form class="layui-form">
            {if $id}
                <input type="hidden" name="id" value="{$id}">
            {/if}
          <div class="layui-form-item">
              <label class="layui-form-label">
                  <span class="x-red">*</span>所属分类
              </label>
              <div class="layui-input-inline">
                  <select name="cat_id">
                      <option value="">请选择分类</option>
                      {volist name="cate" id="v"}
                      <option value="{$v.id}" {eq name='v.id' value='$res.cat_id'}selected{/eq}>{$v.name}</option>
                      {/volist}
                  </select>
              </div>
          </div>

          <div class="layui-form-item">
            <label for="title" class="layui-form-label">
                <span class="x-red">*</span>文章标题
            </label>
            <div class="layui-input-inline">
                <input type="text" id="title" name="title" required="" lay-verify="required"
                       autocomplete="off" class="layui-input" value="{$res.title}">
            </div>
          </div>

            <div class="layui-upload layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>新闻缩略图
                </label>
                <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
                <button type="button" class="layui-btn" id="test9">开始上传</button>
                <input type="hidden" name="thumbnail" value="{$res.thumbnail}" id="ad_img">

                <div class="layui-upload-list" style="display: {if !$res}none{/if};">
                    <label class="layui-form-label"></label>
                    <img class="layui-upload-img" id="demo1" src="{if $res}{:config('imgRoute')}{$res.thumbnail}{/if}">
                    <p id="demoText"></p>
                </div>
            </div>

            <div class="layui-form-item">
                <label for="keywords" class="layui-form-label">
                    关键词
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="keywords" name="keywords"
                           autocomplete="off" class="layui-input" value="{$res.keywords}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    多个关键词，用空格隔开
                </div>
            </div>

            <div class="layui-form-item">
                <label for="link" class="layui-form-label">
                    关键词链接
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="link" name="link"
                           autocomplete="off" class="layui-input" value="{$res.link}">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    用于每个关键词
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label for="desc" class="layui-form-label"><span class="x-red">*</span>文章内容</label>
                <div class="layui-input-block">
                    <textarea id="desc" name="desc" style="display: none;" lay-verify="content">{$res.desc}</textarea>
                </div>
            </div>

          <div class="layui-form-item">
              <label for="L_repass" class="layui-form-label">
              </label>
              <button  class="layui-btn" lay-filter="edit" lay-submit="" id="L_repass">
                  {$id ? '修改' : '增加'}
              </button>
          </div>
      </form>
    </div>
    <script>
        $(function (){
            layui.use(['form', 'layedit', 'upload'], function(){
                var upload = layui.upload;
                var form = layui.form;
                // 同步提交编辑器
                var layedit = layui.layedit;
                // 插入图片
                layedit.set({
                    uploadImage: {
                        url: '{:url("article_upload")}'
                        ,type: 'post',
                    }
                });

                var index = layedit.build('desc'); //建立编辑器
                form.verify({
                    content: function(value) {
                        return layedit.sync(index);
                    }
                });

                // 上传图片
                var url = '{:url("article_upload")}';
                uploadImg(upload, url);

                formData('{:url("article/article_form")}', 'edit', function (){
                    parent.location.reload();
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                }, false);
            });
        })
    </script>
  {/block}